package com.ctsi.security.event.organ;


import com.ctsi.commons.event.AbstractObserver;
import com.ctsi.commons.event.BaseEvent;
import com.ctsi.framework.common.startrun.ComponentFactory;
import com.ctsi.organise.common.model.UserLogin;
import com.ctsi.security.manager.impl.SecurityImpl;

/**
 * 处理组织结构删除登陆用户的事件 
 * 
 * @author gbk
 *
 */

public class DelLoginUserEvent extends AbstractObserver {
	private static org.slf4j.Logger logger=org.slf4j.LoggerFactory.getLogger(DelLoginUserEvent.class);
	private static OrganEventService organEventService;

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = -4660176672618448240L;
	

	@Override
	public void onEvent(Object[] args) {
		logger.info("权限组织事件处理：组织结构删除登陆用户");
		BaseEvent event = (BaseEvent)args[0];
	    UserLogin userLogin=(UserLogin) event.getSource();
	    organEventService=this.getOrganEventService();
	    organEventService.delLoginUserEvent(userLogin.getId());
	    //清除缓存
	    SecurityImpl.removeCacheUserRoles(userLogin.getId());
	    
	}
	
	private OrganEventService getOrganEventService(){
		if(organEventService==null){
			organEventService=(OrganEventService) ComponentFactory.getApplicationContext().getBean("organEventService");
		}
		return organEventService;
	}

}
